import java.util.Scanner;

public class Solution {
    public int minSubArrayLen(int target, int[] nums){
        int sum = 0,len = Integer.MAX_VALUE,n = nums.length;
        for (int left = 0,right = 0;right < n;right++){
            sum += nums[right];//进窗口
            while(sum >= target){//判断
                len = Math.min(len,right-left+1);//更新子数组长度
                sum -= nums[left++];//出窗口
            }
        }
        return len == Integer.MAX_VALUE ? 0 : len;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()){
            int target = in.nextInt();
            int size = in.nextInt();
            int[] arr = new int[size];
            for (int i = 0; i < size; i++) {
                arr[i] = in.nextInt();
            }
            Solution solution = new Solution();
            System.out.println(solution.minSubArrayLen(target, arr));
        }
    }
}
